//
//  ViewController.m
//  GCDTimerTest
//
//  Created by 小零钱 on 2019/5/10.
//  Copyright © 2019 QLing. All rights reserved.
//

#import "ViewController.h"
#import "QLTimer.h"

@interface ViewController ()

@property (nonatomic, copy) NSString * task1;
@property (nonatomic, copy) NSString * task2;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSLog(@"begin");
//    [self demo1];
    [self demo2];
}

//block方式
- (void)demo1 {
    self.task1 = [QLTimer executeTask:^{
        NSLog(@"111 -- %@", [NSThread currentThread]);
    } start:2.f interval:1.f repeats:YES async:NO];
}

//id、target方式
- (void)demo2 {
    self.task2 = [QLTimer executeTask:self selector:@selector(task2Event) start:2.f interval:1.f repeats:YES async:YES];
}
- (void)task2Event {
    NSLog(@"222 -- %@", [NSThread currentThread]);
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    if(self.task1) [QLTimer cancelTask:self.task1];
    if(self.task2) [QLTimer cancelTask:self.task2];
}


@end
